Page({
  data: {
    dateLabel: '9月18日',
    mealLabel: '早餐',
    activeTab: 'common',
    leftTabs: [
      { key: 'common', name: '常见' },
      { key: 'recipes', name: '食谱' },
      { key: 'fav', name: '收藏' },
      { key: 'set', name: '套餐' },
      { key: 'upload', name: '我的上传' },
      { key: 'mine', name: '我的菜肴' },
      { key: 'staple', name: '主食' },
      { key: 'fruit', name: '蔬果' },
      { key: 'egg', name: '肉蛋奶' },
      { key: 'bean', name: '豆类坚果' },
      { key: 'juice', name: '零食饮料' },
      { key: 'food', name: '中西菜肴' },
    ],
    foodList: [
      { id: 1, name: '番茄', cal: 32, unit: '1个(大)', image: '/static/upload/meishi1.jpg' },
      { id: 2, name: '番茄炒蛋', cal: 84, unit: '100克', image: '/static/upload/meishi2.jpg' },
      { id: 3, name: '空心菜', cal: 19, unit: '100克', image: '/static/upload/meishi3.jpg' },
      { id: 4, name: '炒鸡蛋', cal: 119, unit: '80克', image: '/static/upload/meishi4.jpg' },
      { id: 5, name: '米饭', cal: 209, unit: '1碗', image: '/static/upload/meishi5.jpg' }
    ]
  },
  onLoad(options) {
    if (options && options.meal) {
      // 解码URL编码的用餐类型
      const decodedMeal = decodeURIComponent(options.meal);
      this.setData({ mealLabel: decodedMeal });
    }
    // 设置标题：顶部日期 + 用餐类型
    this.updateTitle();
  },
  
  updateTitle() {
    wx.setNavigationBarTitle({ 
      title: `${this.data.dateLabel} ${this.data.mealLabel}` 
    });
  },
  goBack() { wx.navigateBack(); },
  onScan() { wx.showToast({ title: '扫描条形码(示例)', icon: 'none' }); },
  onDone() { wx.navigateBack(); },
  onTabTap(e) { this.setData({ activeTab: e.currentTarget.dataset.key }); },
  addFood(e) { wx.showToast({ title: '已添加(示例)', icon: 'success' }); },
  goSearch() { wx.navigateTo({ url: '/pages/health/search/search' }); },
  goAddFood() { wx.navigateTo({ url: '/pages/health/addfood/addfood' }); }
})

